package com.empire.module.sporttery.service.football500rangzhiim;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.sporttery.controller.admin.football500rangzhiim.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500rangzhiim.Football500RangzhiImDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.sporttery.dal.mysql.football500rangzhiim.Football500RangzhiImMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.sporttery.enums.ErrorCodeConstants.*;

/**
 * 让球实时 Service 实现类
 *
 * @author 无敌仙人
 */
@Service
@Validated
public class Football500RangzhiImServiceImpl implements Football500RangzhiImService {

    @Resource
    private Football500RangzhiImMapper football500RangzhiImMapper;

    @Override
    public Integer createFootball500RangzhiIm(Football500RangzhiImSaveReqVO createReqVO) {
        // 插入
        Football500RangzhiImDO football500RangzhiIm = BeanUtils.toBean(createReqVO, Football500RangzhiImDO.class);
        football500RangzhiImMapper.insert(football500RangzhiIm);
        // 返回
        return football500RangzhiIm.getId();
    }

    @Override
    public void updateFootball500RangzhiIm(Football500RangzhiImSaveReqVO updateReqVO) {
        // 校验存在
        validateFootball500RangzhiImExists(updateReqVO.getId());
        // 更新
        Football500RangzhiImDO updateObj = BeanUtils.toBean(updateReqVO, Football500RangzhiImDO.class);
        football500RangzhiImMapper.updateById(updateObj);
    }

    @Override
    public void deleteFootball500RangzhiIm(Integer id) {
        // 校验存在
        validateFootball500RangzhiImExists(id);
        // 删除
        football500RangzhiImMapper.deleteById(id);
    }

    private void validateFootball500RangzhiImExists(Integer id) {
        if (football500RangzhiImMapper.selectById(id) == null) {
            throw exception(FOOTBALL500_RANGZHI_IM_NOT_EXISTS);
        }
    }

    @Override
    public Football500RangzhiImDO getFootball500RangzhiIm(Integer id) {
        return football500RangzhiImMapper.selectById(id);
    }

    @Override
    public PageResult<Football500RangzhiImDO> getFootball500RangzhiImPage(Football500RangzhiImPageReqVO pageReqVO) {
        return football500RangzhiImMapper.selectPage(pageReqVO);
    }

}